﻿using System;
using System.Collections;

namespace QAHelper.Common
{
    public class XMLLogger:Logger
    {
        #region Properties and Variables
        string _testCaseName = string.Empty;
        string _logFileName = string.Empty;
        string _description = string.Empty;
        static ArrayList _logList = new ArrayList();        

        public string ThisDateTime
        {
            set { ;}
            get { return DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss"); }
        }

        public string TestCaseName
        {
            set { _testCaseName = value; }
            get { return _testCaseName;}
        }
        public string LogFileName
        {
            set { _logFileName = value; }
            get { return _logFileName; }
        }
        public string Description
        {
            set { _description = value; }
            get { return _description; }
        }
        static ArrayList LogList
        {
            set { _logList = value; }
            get { return _logList; }
        }
        #endregion

        #region Functions
        public override void WriteStatus(string expected, string actual, string status, string verification_condition)
        {
            try
            {
                Test_Case testCase = new Test_Case();
                testCase.Test_Case_Name = base.TestCaseName;
                testCase.Expected_Result = expected;
                testCase.Actual_Result = actual;
                testCase.Logging_Time = ThisDateTime;
                testCase.Pass_Fail_Status = status;
                testCase.Reason = "N/A";
                testCase.Verification_Condition = verification_condition;                
                LogList.Add(testCase);
            }
            catch (Exception exp)
            {
                Console.Write("Exception occured from Write Status: {0}", exp.Message);
            }

        }
        public override void WriteStatus(string expected, string actual, string status, string verification_condition,string reason)
        {
            try
            {
                Test_Case testCase = new Test_Case();
                testCase.Test_Case_Name = base.TestCaseName;
                testCase.Expected_Result = expected;
                testCase.Actual_Result = actual;
                testCase.Logging_Time = ThisDateTime;
                testCase.Pass_Fail_Status = status;
                testCase.Reason = reason;
                testCase.Verification_Condition = verification_condition;
                LogList.Add(testCase);
            }
            catch (Exception exp)
            {
                Console.Write("Exception occured from Write Status with reason: {0}", exp.Message);
            }
        }
        public override void WriteLogIntoFile()
        {
            //Test_Case[] testCases = new Test_Case[LogList.Count];
            //Test_Cases testCollection = new Test_Cases();

            //int index = 0;

            //foreach (Test_Case testCase in LogList)
            //{
            //    testCases[index] = testCase;
            //    index++;
            //}
            //testCollection.cases = testCases;

            TestLog[] tLog = new TestLog[LogList.Count];

            int index = 0;
            foreach (Test_Case testCase in LogList)
            {
                tLog[index] = new TestLog();
                tLog[index].Test_Case_Name = testCase.Test_Case_Name;
                tLog[index].Expected_Result = testCase.Expected_Result;
                tLog[index].Actual_Result = testCase.Actual_Result;
                tLog[index].Pass_Fail_Status = testCase.Pass_Fail_Status;
                tLog[index].Reason = testCase.Reason;
                tLog[index].Logging_Time = testCase.Logging_Time;
                index++;
            }
            
            XMLHelper.Serialize(base.LogFileName+base.FileExtention, tLog);
        }
        public override void WriteLogIntoFile(string workSheetName)
        {
            WriteLogIntoFile();
        }
        #endregion

    }
}
